using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using System.Data.SqlClient;
using HHo_Model;
using System.Configuration;


namespace HHo_Negocio
{
    public class GestorPMS
    {
        private SqlParameter oPrm;
        private SqlDataReader oRdr;
        private List<E_Flota> lstFlotas;
        private E_Flota oFlota;


        public bool VerificarExisteMat(string strMat)
        {
            bool returnValue = false;
            SqlParameter oP1 = new SqlParameter("@MATAVI", SqlDbType.Char);
            oP1.Size = 10;
            oP1.Direction = ParameterDirection.Input;
            oP1.Value = strMat;
            try
            {
                SQLHelper.ExecuteScalar(SQLHelper.ObtieneCadenaConexion(), CommandType.StoredProcedure, "[HHSS_AVIONES_PMS]", oP1);
                returnValue = true;
            }
            catch
            {
                throw;
            }
            return returnValue;
        }


        public List<E_Flota> ListarFlotas()
        {
            oRdr = SQLHelper.ExecuteReader(SQLHelper.ObtieneCadenaConexion(), CommandType.StoredProcedure, "USP_LISTAR_FLOTAS");

            if (oRdr != null)
            {
                lstFlotas = new List<E_Flota>();
                while (oRdr.Read())
                {
                    oFlota = new E_Flota();
                    if (oRdr.GetValue(0) != DBNull.Value)
                        oFlota.Codigo = oRdr.GetInt32(0);

                    if (oRdr.GetValue(1) != DBNull.Value)
                        oFlota.Marca = oRdr.GetString(1);

                    if (oRdr.GetValue(2) != DBNull.Value)
                        oFlota.Modelo = oRdr.GetString(2);

                    if(oRdr.GetValue(3) != DBNull.Value)
                        oFlota.Descripcion = oRdr.GetString(3);

                    if (oRdr.GetValue(4) != DBNull.Value)
                        oFlota.Estado = oRdr.GetBoolean(4);

                    lstFlotas.Add(oFlota);
                    oFlota = null;
                }
            }
            return lstFlotas;
        }
    }
}
